﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint.New
{
    /// <summary>
    /// A PowerPoint TextRange object that can resolve itself from serializable info.
    /// </summary>
    [XmlInclude(typeof(ResolvableSimpleTextRange)),
    XmlInclude(typeof(ResolvableTableTextRange))]
    public abstract class ResolvableTextRange : ResolvableObject
    {
        Ppt.TextRange mTextRange;
        int mStart;
        int mLength;

        public int Start
        {
            get { return TextRange.Start; }
            set { mStart = value; }
        }

        public int Length
        {
            get { return TextRange.Length; }
            set { mLength = value; }
        }

        public ResolvableTextRange() { } // Parameterless constructor required for deserialization.

        public ResolvableTextRange(Ppt.TextRange textRange)
        {
            //Start = textRange.Start;
            //Length = textRange.Length;
            mTextRange = textRange;
        }

        [XmlIgnore]
        public Ppt.TextRange TextRange
        {
            get
            {
                if (mTextRange == null)
                    mTextRange = this.Resolve() as Ppt.TextRange;

                return mTextRange;
            }

            set { mTextRange = value; }
        }

        [XmlIgnore]
        public abstract Ppt.Shape Shape { get; }

        public override object Resolve()
        {
            return Shape.TextFrame.TextRange.Characters(mStart, mLength);
        }

        public abstract ResolvableShape GetParentShape();

        [XmlIgnore]
        public abstract bool Selected { get; }

        [XmlIgnore]
        public abstract bool ContainsSelection { get; }
    }
}
